const query = require("../db/mysql")
const { success, error } = require("../module/module")

class Area {
    sheng = async (ctx) => {
        let sql = `select * from provinces where 1=1 `
        let data = await query(sql)
        ctx.body = {
            code: 1,
            data
        }
    }
    shi = async (ctx) => {
        let { provinceid } = ctx.request.body
        let sql = `select * from cities where 1=1 `
        if (provinceid) {
            sql += `and provinceid=${provinceid}`
        }
        let data = await query(sql)
        ctx.body = {
            code: 1,
            data
        }

    }
    xian = async (ctx) => {
        let { cityid } = ctx.request.body
        let sql = `select * from areas where 1=1 `
        if (cityid) {
            sql += `and cityid=${cityid} `
        }
        let data = await query(sql)
        ctx.body = {
            code: 1,
            data
        }
    }
}

module.exports = new Area()